package com.ruoyi.wlxz.util;

import com.ruoyi.wlxz.domain.WxzPublishedActivity;
import com.ruoyi.wlxz.service.IWxzPublishedActivityService;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class QuartzActivityJob implements Job {
    @Autowired
    private IWxzPublishedActivityService wxzPublishedActivityService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //修改活动状态
        JobDataMap jobDataMap = jobExecutionContext.getMergedJobDataMap();
        String type = jobDataMap.getString("type");
         String ActivityName= jobDataMap.getString("ActivityName");
        WxzPublishedActivity wxzPublishedActivity = new WxzPublishedActivity();
        wxzPublishedActivity.setActivityName(ActivityName);
        if ("报名中".equals(type)) {
            // 执行活动相关业务逻辑
            System.out.println("执行活动报名中相关任务");
            //修改数据库活动状态
            wxzPublishedActivity.setStatus("报名中");
            int i = wxzPublishedActivityService.updateWxzPublishedActivity(wxzPublishedActivity);
            System.out.println("执行活动报名中相关任务"+ActivityName+"状态"+i);
        } else if ("进行中".equals(type)) {
            // 执行活动进行中相关业务逻辑
            System.out.println("执行活动进行中相关任务");
            wxzPublishedActivity.setStatus("进行中");
            int i = wxzPublishedActivityService.updateWxzPublishedActivity(wxzPublishedActivity);
            System.out.println("执行活动进行中相关任务"+ActivityName+"状态"+i);
        } else if ("已结束".equals(type)) {
            // 执行活动已结束相关业务逻辑
            System.out.println("执行活动已结束相关任务");
            wxzPublishedActivity.setStatus("已结束");
            int i = wxzPublishedActivityService.updateWxzPublishedActivity(wxzPublishedActivity);
            System.out.println("执行活动已结束相关任务"+ActivityName+"状态"+i);
        } else if ("等待中".equals(type)) {
            // 执行活动等待中相关业务逻辑
            System.out.println("执行活动等待中相关任务");
            wxzPublishedActivity.setStatus("等待中");
            int i = wxzPublishedActivityService.updateWxzPublishedActivity(wxzPublishedActivity);
            System.out.println("执行活动等待中相关任务"+ActivityName+"状态"+i);
        }
    }
}